package eu.jpereira.trainings.designpatterns.structural.facade;



import eu.jpereira.trainings.designpatterns.structural.facade.BookstoreFacade;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Book;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Customer;
import eu.jpereira.trainings.designpatterns.structural.facade.model.DispatchReceipt;
import eu.jpereira.trainings.designpatterns.structural.facade.model.Order;
import eu.jpereira.trainings.designpatterns.structural.facade.service.BookDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerDBService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.CustomerNotificationService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.OrderingService;
import eu.jpereira.trainings.designpatterns.structural.facade.service.WharehouseService;

public class DefaultBooktoreFacade implements BookstoreFacade {

	BookDBService bookDBService;
	CustomerDBService customerDBService;
	CustomerNotificationService customerNotificationService;
	OrderingService orderingService;
	WharehouseService wharehouseService;
	
	public DefaultBooktoreFacade() {
	}

	@Override
	public void placeOrder(String customerId, String isbn) {
		Book book = bookDBService.findBookByISBN(isbn);
		
		Customer customer=customerDBService.findCustomerById(customerId);
		
		Order order = orderingService.createOrder(customer, book);
		
		DispatchReceipt receipt=wharehouseService.dispatch(order);
		
		customerNotificationService.notifyClient(receipt);
		
		customerNotificationService.notifyClient(order);
	}
	
	public void setBookDBService(BookDBService service) {
		this.bookDBService=service;
	}
	
	public void setCustomerDBService(CustomerDBService service) {
		this.customerDBService=service;
	}
	
	public void setCustomerNotificationService(CustomerNotificationService service) {
		this.customerNotificationService=service;
	}
	
	public void setOrderingService(OrderingService service) {
		this.orderingService=service;
	}
	
	public void setWharehouseService(WharehouseService service) {
		this.wharehouseService=service;
	}
}
